package com.example.sharding.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.sharding.enerty.TOrder;
import com.example.sharding.dao.TOrderMapper;
import com.example.sharding.service.TOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jodd.util.StringUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 订单表
 * </p>
 *
 * @author 杨二狗
 * @since 2022-03-06 15:10:34
 */
@Service
public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> implements TOrderService {
    @Resource
    private TOrderMapper tOrderMapper;

    /**
     * 单增
     */
    @Override
    public int insertTOrder(TOrder tOrder){
        return tOrderMapper.insert(tOrder);
    }
    /**
     * 批量删除
     */
    @Override
    public int deleteTOrderBatchIds(List<String> tOrderIds){
        return tOrderMapper.deleteBatchIds(tOrderIds);
    }
    /**
     * 修改
     */
    @Override
    public int updateTOrder(TOrder tOrder){

//        QueryWrapper<TOrder> queryWrapper = new QueryWrapper<>();
//        queryWrapper.lambda().eq(StringUtil.isNotEmpty(tOrder.getLoginName()),TOrder::getLoginName,tOrder.getLoginName());
//        return tOrderMapper.update(tOrder,queryWrapper);
        return tOrderMapper.updateById(tOrder);
    }
    /**
     * 查询
     */
    @Override
    public List<TOrder> selectTOrderList(TOrder tOrder){
        /*
        查询条件,是什么条件查询就自己灵活补充,例子:将登陆名字(LoginName)等等(eq)作为查询条件
         */
        QueryWrapper<TOrder> queryWrapper = new QueryWrapper<>();
//        queryWrapper.lambda().eq(StringUtil.isNotEmpty(tOrder.getLoginName()),TOrder::getLoginName,tOrder.getLoginName());
        return tOrderMapper.selectList(queryWrapper);
    }
    /**
     * 分页查询
     */
    @Override
    public IPage<TOrder> selectTOrderPage(TOrder tOrder){
        QueryWrapper<TOrder> queryWrapper = new QueryWrapper<>();
//        queryWrapper.lambda().eq(StringUtil.isNotEmpty(tOrder.getLoginName()),TOrder::getLoginName,tOrder.getLoginName());
//        queryWrapper.lambda().orderByDesc(TOrder::getLoginName);
        IPage<TOrder> tOrderPage = new Page<>(2,2);

        return tOrderMapper.selectPage(tOrderPage,queryWrapper);
    }


}
    